<html>
<head>
<script type="text/javascript">
function tiao()
{
	var go=document.getElementById('go').value;
	if(!isNaN(go))
	{
	    location.href='empslist.php?pagenow='+go;
	}
	else
	{
	    alert('必须输入数字');
	}
}
</script>
</head>
</html>
<?php
//
header("content-type:text/html;charset=utf-8");
// 显示所有用户
$con = mysql_connect('localhost', 'root', 'dx123');
if (! $con) {
    die("出错了" . mysql_errno());
}
// 选择数据库
mysql_select_db("empmanage");
// 构建语句查询出记录数
$sql1 = "select count(id) from emps";
// 执行
$result = mysql_query($sql1);
if (! empty($result)) {
    $rows = mysql_fetch_row($result);
    $count = $rows[0];
}
// 分页
$pagenow = 1;
if (isset($_GET['pagenow'])) {
    $pagenow = $_GET['pagenow'];
}
$pagecount = 3;
$pageall = ceil($count / $pagecount);
$pagestart = ($pagenow - 1) * $pagecount;
$sql = "select * from emps limit $pagestart,$pagecount";
// 执行
$res = mysql_query($sql);
// 打印到页面上
echo "<table border=1 bordercolor='green' cellspacing=0><tr><th>id</th><th>name</th><th>mail</th><th>grade</th><th>salary</th><tr>";
while ($row = mysql_fetch_row($res)) {
    echo "<tr>";
    for ($i = 0; $i < count($row); $i ++) {
        echo "<td>$row[$i]</td>";
    }
    echo "</tr>";
}
$pageup = $pagenow - 1;
$pagedown = $pagenow + 1;
echo "</table>";
if ($pagenow != 1) {
    echo "<a href='empslist.php?pagenow=$pageup'>上一页</a>";
} else {
    echo '上一页';
}
for ($i = 1; $i <= $pageall; $i ++) {
    
    if ($pagenow == $i) {
        echo $i;
    } else {
        echo "<a href='empslist.php?pagenow=$i'>" . "$i" . "</a>&nbsp";
    }
}
if ($pagenow != $pageall) {
    echo "<a href='empslist.php?pagenow=$pagedown'>下一页</a>";
} else {
    echo '下一页<br/>';
}
echo "<br/>指定到<input type='text' id='go' style='width:30px'/>页<input type='button' value='跳' onclick='tiao()'/>";


    
    